package com.example.hello.controller;

import com.example.hello.pojo.PaymentLog;
import com.example.hello.pojo.Res;
import com.example.hello.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    /** 账户充值 */
    @PostMapping("/recharge")
    public Res recharge(
        @RequestParam Long userId,
        @RequestParam BigDecimal amount
    ) {
        BigDecimal newBalance = paymentService.recharge(userId, amount);
        return Res.success(newBalance);
    }

    /** 逾期缴费 */
    @PostMapping("/overdue")
    public Res payOverdue(
        @RequestParam Long userId,
        @RequestParam BigDecimal amount
    ) {
        paymentService.payOverdue(userId, amount);
        return Res.success();
    }

    /** 获取支付流水 */
    @GetMapping("/logs/{userId}")
    public Res getLogs(@PathVariable Long userId) {
        List<PaymentLog> logs = paymentService.getPaymentLogs(userId);
        return Res.success(logs);
    }
}